package com.pacifictextiles.qc.inspection.server.model.test;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pacifictextiles.qc.inspection.server.model.dao.impl.RollDAOImpl;
import com.pacifictextiles.qc.inspection.server.model.vo.Roll;

/**
 * Servlet implementation class AddRoll
 */
public class AddRoll extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddRoll() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 设置数据编码
		response.setContentType("text/html; charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		
		// 获取参数
		Roll roll = new Roll();
		roll.setCpi(Float.parseFloat(request.getParameter("cpi")));
		roll.setDefectCount(Integer.parseInt(request.getParameter("defectCount")));
		roll.setExpRollNo(request.getParameter("expRollNo"));
		roll.setFabricWeight(Float.parseFloat(request.getParameter("fabricWeight")));
		roll.setFullCode(request.getParameter("fullCode"));
		roll.setGrossLength(Float.parseFloat(request.getParameter("grossLength")));
		roll.setInspectStatus(Boolean.parseBoolean(request.getParameter("inspectStatus")));
		roll.setNetLength(Float.parseFloat(request.getParameter("netLength")));
		roll.setOperatorId(request.getParameter("operatorId"));
		roll.setQualityLevel(Integer.parseInt(request.getParameter("qualityLevel")));
		roll.setRollNo(request.getParameter("rollNo"));
		roll.setSpace(Float.parseFloat(request.getParameter("space")));
		roll.setStationId(request.getParameter("stationId"));
		roll.setTotalpoints(Integer.parseInt(request.getParameter("totalPoints")));
		roll.setTubeWeight(Float.parseFloat(request.getParameter("tubeWeight")));
		roll.setWasteLength(Float.parseFloat(request.getParameter("wasteLength")));
		roll.setWeightingStatus(Boolean.parseBoolean(request.getParameter("weightingStatus")));
		roll.setWidth(Float.parseFloat(request.getParameter("width")));
		roll.setWpi(Float.parseFloat(request.getParameter("wpi")));
		
		// 执行数据库操作
		RollDAOImpl rdi = new RollDAOImpl();
		try {
			
			//addRoll()已变成String类型
			if (rdi.finishUpdateRoll(roll) == true) {
				System.out.println("Update roll success!");
			} else {
				System.out.println("Update roll faild");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
